package gpool

import "sync"

/**
协程池
 */

type Pool struct {
	Wg *sync.WaitGroup
	PoolChan chan bool
}

func NewPool(num int) *Pool {
	return &Pool{
		Wg: &sync.WaitGroup{},
		PoolChan: make(chan bool, num),
	}
}

func (p *Pool) Add() {
	p.PoolChan <- true
	p.Wg.Add(1)
}

func (p *Pool) Done() {
	p.Wg.Done()
	<- p.PoolChan
}

func (p *Pool) Wait() {
	p.Wg.Wait()
}

